import {ElMessage} from "element-plus";

const messageError = (msg: string)=>{
    ElMessage({message: msg, type: "error"});
}

const messageSuccess = (msg: string)=>{
    ElMessage({message: msg, type: "success"});
}

const messageWarning = (msg: string)=>{
    ElMessage({message: msg, type: "warning"});
}

const messageInfo = (msg: string)=>{
    ElMessage({message: msg, type: "info"});
}

const handleResponseMessage = (res: { success: boolean; message: string }, successMessage: string | undefined = undefined)=>{
    if (res.success){
        if (successMessage){
            messageSuccess(successMessage);
        }else {
            messageSuccess(res.message);
        }
    }else {
        messageError(res.message);
    }
}

export {
    messageError,
    messageSuccess,
    messageWarning,
    messageInfo,
    handleResponseMessage
}
